package com.social.controller;

import com.alibaba.fastjson.JSON;
import com.social.pojo.TerminationOfFilingForm;
import com.social.service.TerminationOfFilingFormService;
import com.social.util.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * 终止立案原因管理
 */
@Controller
@RequestMapping("terminationOfFilingForm")
public class TerminationOfFilingFormController {
    /**
     * TerminationOfFilingForm 业务层
     */
    @Autowired
    private TerminationOfFilingFormService terminationOfFilingFormService;

    /**
     * 添加方法
     *
     * @param terminationOfFilingForm 实体类
     * @param session                 作用域
     * @return 添加或修改状态
     */
    @RequestMapping("insert")
    @ResponseBody
    public String insertOrUpdate(TerminationOfFilingForm terminationOfFilingForm, HttpSession session) {
        Integer ids = (Integer) session.getAttribute("ids");
        TerminationOfFilingForm terminationOfFilingForm1 = terminationOfFilingFormService.selectByPrimaryKey(ids);
        int status = 0;
        if (terminationOfFilingForm1 == null) {
            status = terminationOfFilingFormService.insert(terminationOfFilingForm);
        } else {
            status = terminationOfFilingFormService.updateByRegistrationOfCasesId(terminationOfFilingForm);
        }
        JsonUtil jsonUtil = new JsonUtil();
        //设置状态
        Boolean restates = jsonUtil.getRestates(status);
        return JSON.toJSONString(restates);
    }
}
